package com.yunfangdata.service.impl;

import com.yunfangdata.domain.DataDict;
import com.yunfangdata.mapper.DataDictMapper;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.service.IDataDictService;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataDictServiceImpl implements IDataDictService {


    @Autowired
    private DataDictMapper mapper;

    public void save(DataDict entity) {
        mapper.insert(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void update(DataDict entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public DataDict get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<DataDict> list() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = mapper.queryForCount(qo);

        if (total == 0){
            return new PageResult();
        }
        List<DataDict> rows = mapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    public List<DataDict> selectDataDictByperentId(Long perentId) {
        return mapper.selectDataDictByperentId(perentId);
    }
    //查询父类 数据字典
    public List<DataDict> queryByParentIdIsNull() {
        return mapper.queryByParentIdIsNull();
    }

    public List<DataDict> queryByParentIdChildren(Long parentId) {
        return mapper.queryByParentIdChildren(parentId);
    }

    public List<DataDict> queryByParentId(Long id) {

        return mapper.queryByParentId(id);
    }




}
